package objects

import (
	"net/http"
	"strings"
	"os"
	"ones-objects/config"
	"io"
)

func put(w http.ResponseWriter, r *http.Request)  {
	path := r.URL.EscapedPath()

	fileName := strings.Split(path, "/")[2]


	f, err := os.Create(config.GetString(config.OBJECTS_LOCAL_PATH) + config.OBJECTS_PATH + fileName)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(config.ERROR_OPEN_FILE))
		return
	}
	defer f.Close()

	io.Copy(f, r.Body)
}
